package ITA.QQ;



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.plaf.FontUIResource;

public class ChatFrame extends JFrame implements ActionListener{
	private JTextArea chatTa;      //聊天显示框
	private JList friendsTa;   //朋友列表框
	private JTextArea sendTa;    //输入框
	private JButton sendBtn;   //发送
	private JButton deleteBtn; //删除
	private JButton shakeBtn;  //抖动按钮
	private ImageIcon headPortrait; //头像
	private JLabel commentlabel;//包装头像
	private JLabel account;   //显示用户名
	private JLabel sign;   //显示签名
	
	
	public ChatFrame() {
		this.setSize(600, 500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.setDefaultLookAndFeelDecorated(isDefaultLookAndFeelDecorated());
		JFrame.setDefaultLookAndFeelDecorated(true);
		init();
		addEvent();
		this.setVisible(true);
		
	}
	private void init(){
		this.setLayout(new BorderLayout());
		JPanel panLeft=new JPanel(new BorderLayout());   //左侧panel
		JPanel panRight=new JPanel(new BorderLayout());  //右侧panel
		JPanel panLeftBottom=new JPanel(new BorderLayout());  //左侧底部构建
		JPanel panBtnGroup=new JPanel(new BorderLayout());   //左侧底部西边按钮组
		JPanel panlRightTop=new JPanel(new BorderLayout());   //右侧顶端
		JPanel panlRightTopRight=new JPanel(new BorderLayout());   //右侧顶端右侧账号签名
		
		chatTa=new JTextArea(10,20);
		chatTa.setLineWrap(true);
		friendsTa=new JList();
		sendTa=new JTextArea(4,7);
		deleteBtn=new JButton("Delete");
		sendBtn=new JButton("Send");
		shakeBtn=new JButton("Shake");
		headPortrait=new ImageIcon("gxr1000.jpg");
        commentlabel = new JLabel("", headPortrait,JLabel.CENTER);
        commentlabel.setBounds(450, 20, 60, 60);
        account=new JLabel("Angers");
        sign=new JLabel("someone");
		
        account.setFont(new Font("隶书",Font.PLAIN, 16));
        account.setForeground(Color.darkGray);
		sendTa.setFont(new Font("隶书",Font.PLAIN, 16));
		sendTa.setForeground(Color.darkGray);
		sendTa.setFont(new Font("隶书",Font.PLAIN, 16));
		sendTa.setForeground(Color.darkGray);
		chatTa.setFont(new Font("隶书",Font.PLAIN, 16));
		chatTa.setForeground(Color.darkGray);
		sendBtn.setFont(new Font("隶书",Font.PLAIN, 16));
		sendBtn.setForeground(Color.darkGray);
		shakeBtn.setFont(new Font("隶书",Font.PLAIN, 16));
		shakeBtn.setForeground(Color.darkGray);
		deleteBtn.setFont(new Font("隶书",Font.PLAIN, 16));
		deleteBtn.setForeground(Color.darkGray);
		
		account.setFont(new Font("隶书",Font.PLAIN, 16));
		account.setForeground(Color.darkGray);
		sign.setFont(new Font("隶书",Font.PLAIN, 16));
		sign.setForeground(Color.darkGray);
		
		
		friendsTa.setFont(new Font("隶书",Font.PLAIN, 26));
		friendsTa.setForeground(Color.darkGray);
		
		//设置好友框List
		final DefaultListModel defaultName = new DefaultListModel();

        defaultName.addElement("Lady Finger");
        defaultName.addElement("Onion");
        defaultName.addElement("Potato");
        defaultName.addElement("Tomato");
        defaultName.addElement("Jhon");
        defaultName.addElement("Mack");
        defaultName.addElement("Jack");
        defaultName.addElement("Bob");
        defaultName.addElement("Maven");
        defaultName.addElement("Angers");
        defaultName.addElement("Jody");
        defaultName.addElement("Sky");
        defaultName.addElement("Moon");
        defaultName.addElement("Mars");
        defaultName.addElement("Judy");
        defaultName.addElement("Alice");
        friendsTa=new JList(defaultName);
        friendsTa.setSelectionMode(
                ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        friendsTa.setSelectedIndex(0);
        friendsTa.setVisibleRowCount(3);
		//设置背景
		panlRightTopRight.setBackground(Color.lightGray);
		//设置边框
		panRight.setBorder(new LineBorder(Color.gray));
		panLeft.setBorder(new LineBorder(Color.gray));
		panLeftBottom.setBorder(new LineBorder(Color.gray));
		panBtnGroup.setBorder(new LineBorder(Color.gray));
		sendTa.setBorder(new LineBorder(Color.gray));
		commentlabel.setBorder(new LineBorder(Color.gray));
		//设置构建顺序
		panlRightTopRight.add(account,BorderLayout.CENTER);
		panlRightTopRight.add(sign,BorderLayout.SOUTH);
		panlRightTop.add(commentlabel,BorderLayout.WEST);
		panlRightTop.add(panlRightTopRight,BorderLayout.EAST);
		panRight.add(panlRightTop,BorderLayout.NORTH);
		panRight.add(new JScrollPane(friendsTa),BorderLayout.CENTER);
		panLeft.add(new JScrollPane(chatTa), BorderLayout.CENTER);
		panLeft.add(panLeftBottom,BorderLayout.SOUTH);

		this.add(panLeft,BorderLayout.CENTER);
		this.add(panRight,BorderLayout.EAST);
		panBtnGroup.add(shakeBtn,BorderLayout.CENTER);
		panBtnGroup.add(deleteBtn,BorderLayout.NORTH);
		panBtnGroup.add(sendBtn,BorderLayout.SOUTH);
		panLeftBottom.add(new JScrollPane(sendTa),BorderLayout.CENTER);
		panLeftBottom.add(panBtnGroup,BorderLayout.EAST);
	}
	
	private void addEvent(){
		sendBtn.addActionListener(this);
	}
    
	public void actionPerformed(ActionEvent e) {
		String content=sendTa.getText();
		sendTa.setText("");
		System.out.println(content);
		chatTa.append(content+"\n");
	}

}